package com.ity.teamanagement.controller;

import com.ity.teamanagement.annocation.CheckAuthorityStatus;
import com.ity.teamanagement.annocation.CheckLoginState;
import com.ity.teamanagement.code.TeaQrCode;
import com.ity.teamanagement.result.Result;
import com.ity.teamanagement.service.QrCodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author coderFu
 * @create 2021/6/4
 */
@RestController
@Api(tags = "后台二维码模块")
@RequestMapping("/code")
public class QrCodeController {

    @Autowired
    private QrCodeService qrCodeService;

    @PostMapping("/produceOneQrCodeByIds")
    @ApiOperation("根据茶种id生成二维码")
    @CheckLoginState
    public Result produceOneQrCodeById(@RequestBody List<Long> qrIds){
        return Result.success(qrCodeService.produceOneQrCodeById(qrIds));
    }

    @GetMapping("/findAllTeaQrCode")
    @ApiOperation("查询所有茶种二维码")
    @CheckLoginState
    public Result findAllTeaQrCode(@PageableDefault(page = 0,size = 10)Pageable pageable){
        return Result.success(qrCodeService.findAllTeaQrCode(pageable));
    }

    @DeleteMapping("/deleteTeaQrCodeByIds")
    @ApiOperation("根据id删除茶种二维码")
    @CheckAuthorityStatus
    public Result deleteTeaQrCodeByIds(@RequestBody List<Long> ids){
        qrCodeService.deleteTeaQrCodeByIds(ids);
        return Result.success();
    }

    @PostMapping("/downloadTeaQrCodeByIds")
    @ApiOperation("根据二维码id下载二维码")
    @CheckLoginState
    public Result downloadTeaQrCodeByIds(@RequestBody List<Long > ids){
        qrCodeService.downloadTeaQrCodeByIds(ids);
        return Result.success(TeaQrCode.QR_CODE_DOWNLOAD_SUCCESS);
    }


    @PostMapping("/downloadAllTeaQrCodeByIds")
    @ApiOperation("下载所有二维码")
    @CheckLoginState
    public Result downloadAllTeaQrCodeByIds(){
        qrCodeService.downloadAllTeaQrCodeByIds();
        return Result.success(TeaQrCode.QR_CODE_DOWNLOAD_SUCCESS);
    }




}
